package 剑指offerII;

import java.util.HashSet;
import java.util.Set;

public class _119最长连续字序列 {
    public int longestConsecutive(int[] nums) {
        Set<Integer> set = new HashSet<Integer>();
        int res = 0,cur_lon = 1;
        for(int num : nums){
            set.add(num);
        }
        for(int num : set){
            if(!set.contains(num - 1)){
                int cur = num;
                cur_lon = 1;
                while (set.contains(cur + 1)){
                    cur++;
                    cur_lon++;
                }
                res = res > cur_lon ? res : cur_lon;
            }
        }
        return res;
    }
}
